<template>
	<basic-container>
		<avue-crud :option="option" :data="data" v-model="form" :page="page" ref="crud" @search-change="searchChange"
		 @search-reset="searchReset" @current-change="currentChange" @size-change="sizeChange" @row-del="rowDel" @row-update="rowUpdate"
		 @row-save="rowSave" @on-load="onLoad">
		</avue-crud>
	</basic-container>
</template>

<script>
	import request from '@/router/axios';
	export default {
		data() {
			return {
				query: {},
				page: {
					pageSize: 10,
					currentPage: 1,
					total: 0
				},
				form: {},
				option: {
					searchMenuSpan: 4,
					border: true,
					index: true,
					refreshBtn: false,
					excelBtn: true,
					menuWidth: '150px',
					column: [
						{
							label: "纸箱编号",
							prop: "code",
							search: true,
							width:100
						},
						{
							label: "纸箱名称",
							prop: "name",
							width:200
						},
						{
							label: "体积",
							prop: "volume",
							type:'number',
							width:100
						},
						{
							label: "重量",
							prop: "weight",
							type:'number',
							width:100
						},
						{
							label: "长",
							prop: "length",
							type:'number',
							width:100
						},
						{
							label: "宽",
							prop: "width",
							type:'number',
							width:100
						},
						{
							label: "高",
							prop: "height",
							type:'number',
							width:100
						},
						{
							label: "备注",
							prop: "remark"
						}
					]
				},
				data: []
			};
		},
		created() {
		},
		mounted() {},
		methods: {
			rowSave(row, loading, done) {
				this.request({
					url: '2/api/BaseBox/add',
					method: 'post',
					data: row
				}).then(() => {
					loading();
					this.onLoad(this.page);
					done();
				}, error => {
					done();
					console.log(error);
				});
			},
			rowUpdate(row, index, loading, done) {
				return this.request({
					url: '2/api/BaseBox/edit',
					method: 'post',
					data: row
				}).then(() => {
					loading();
					this.onLoad(this.page);
				}, error => {
					done();
					console.log(error);
				});
			},
			rowDel(row) {
				this.$confirm("确定数据删除?", {
						confirmButtonText: "确定",
						cancelButtonText: "取消",
						type: "warning"
					})
					.then(() => {
						return this.request({
							url: '2/api/BaseBox/remove',
							method: 'post',
							params: {
								id: row.id
							}
						});
					})
					.then(() => {
						this.onLoad(this.page);
					});
			},
			searchReset() {
				this.query = {};
				this.page.currentPage = 1;
				this.onLoad(this.page);
			},
			searchChange(params, done) {
				this.page.currentPage = 1;
				this.query = params;
				this.onLoad(this.page);
				done();
			},
			currentChange(currentPage) {
				this.page.currentPage = currentPage;
			},
			sizeChange(pageSize) {
				this.page.pageSize = pageSize;
			},
			onLoad(page) {
				this.request({
					url: '2/api/BaseBox/pages',
					params: {
						key: this.query.code == undefined ? '' : this.query.code,
						type: this.query.name == undefined ? '' : this.query.name,
						page: page.currentPage,
						limit: page.pageSize
					}
				}).then(res => {
					const data = res.data
					this.data = data.data;
					this.page.total = data.remark;
				});
			}
		}
	};
</script>

<style>
</style>
